{% extends '::base.html.twig' %}

{% block body %}

<div class="content">
    <div class="form-row row-fluid" id="div_form_bon_livraison">
        {% include "GdsAchatBundle::BonLivraison/form_bon_livraison.html.twig" %}
        </div>
    </div>
    <script type="text/javascript">


        $(document).ready(function() {
            $('#departement').val({{user.departement.id}})
            $('#departement').attr('disabled', true);
            $('#gds_achatbundle_bonlivraisonfournisseurtype_date').datepicker();
            $('#retour2').hide()
            var fullDate = new Date();
            var twoDigitMonth = fullDate.getMonth()
            twoDigitMonth++
            twoDigitMonth += "";
            if (twoDigitMonth.length == 1)
                twoDigitMonth = "0" + twoDigitMonth;
            var twoDigitDate = fullDate.getDate() + "";
            if (twoDigitDate.length == 1)
                twoDigitDate = "0" + twoDigitDate;
            var currentDate = twoDigitDate + "/" + twoDigitMonth + "/" + fullDate.getFullYear();
            $("#gds_achatbundle_bonlivraisonfournisseurtype_date").val(currentDate)
            setInterval(time, 1000);
            $('#form_bon_livraison').validate();
            $('#submit_form_bon_livraison').click(function() {
                $('#gds_achatbundle_bonlivraisonfournisseurtype_reference').focus()
                if ($('#form_bon_livraison').valid()) {
                    $.ajax({
                        url: '{{path("gds_achat_bon_livraison")}}',
                        type: "POST",
                        datatype: 'json',
                        data: $('#form_bon_livraison').serialize() + '&articles={"articles":' + JSON.stringify(articles) + '}&heure=' + $('#heure').val() + '&facturable=' + $('#facturable').is(':checked') + '&departement=' + $("#departement option:selected").text(),
                        success: function(data) {
                            if (data.success) {
                                $.msgBox({
                                    title: "Bon Livraison",
                                    content: "Enregistrement Effectué avec succés",
                                    type: "info",
                                    buttons: [{value: "OK"}],
                                    success: function(result) {
                                        location.reload();
                                    }
                                });
                            } else {
                                $.msgBox({
                                    title: "Bon Livraison",
                                    content: "Erreur D'enregistrement",
                                    type: "error",
                                    buttons: [{value: "OK"}]
                                });
                            }
                        },
                        error: function(e) {
                            $.msgBox({
                                title: "Bon Livraison",
                                content: "Erreur D'enregistrement",
                                type: "error",
                                buttons: [{value: "OK"}],
                                success: function(result) {

                                }
                            });
                        }
                    })
                }
            })

            Array.prototype.remove = function(v) {
                this.splice(this.indexOf(v) == -1 ? this.length : this.indexOf(v), 1);
            }
            index = 0;
            nb_article = 1;
            // var index_array = Array();
            articles = new Array();
            // On r�cup�re la balise <div> en question qui contient l'attribut � data-prototype � qui nous int�resse
            $container = $('#gds_achatbundle_lignebonlivraisonfournisseurtype');


        });
        $(document).ready(function() {
            $('#show_article').click(function() {
                art = ""
                for (i = 0; i < articles.length; i++)
                    alert(articles[i].id + "   " + articles[i].reference + "  " + articles[i].quantite + "  " + articles[i].remise)
            })
        })

        </script>

        <input type="hidden" id="heure"/>
        <input type="button" value="article" id="show_article">
{% endblock %}    